/**
 * 
 */
package com.cchr.acms.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cchr.acms.model.Drug;
import com.cchr.acms.service.DrugService;
import com.cchr.acms.util.HtmlComponentUtil.SelectOption;

@Controller
@RequestMapping("/html")
public class HtmlController 
{
	@Autowired
	DrugService drugService;
	
    @RequestMapping("/select2")
    public String select2(HttpServletRequest request)
    {
    	List<Drug> drugs = drugService.getAllDrug();
    	List<SelectOption> datas = new ArrayList<SelectOption>();
    	for(Drug drug : drugs)
    	{
    		SelectOption op = new SelectOption();
    		op.setGroup(drug.getType());
    		op.setLabel(drug.getName());
    		op.setValue(String.valueOf(drug.getId()));
    		datas.add(op);
    	}
    	request.setAttribute("datas", datas);
        return "html/select2";
    }
    
}
